package com.life.rule;

import java.awt.Color;
import java.awt.Dimension;

import com.life.model.LifeModel;
import com.life.view.ColorGenerator;

public class ProbabilisticLifeRule extends SBLifeRule {

	
	
	ColorGenerator theColorGenerator = null;
	double [] survivalProbabilities = null;
	double [] birthProbabilities = null;
	
	
	public ProbabilisticLifeRule(double[]sVals,double[]bVals,ColorGenerator gen, String name)
	{
		theName =  name;
		theColorGenerator = gen;
		survivalProbabilities = sVals;
		birthProbabilities = bVals;		
	}
	
	
	public boolean canStayAlive(int neighbors)
	{
		
		double prob = survivalProbabilities[neighbors];
		double guess = Math.random();
		
		if(guess <= prob)
		{
			return true;
		}
		
		return false;
	}
	
	public boolean canCreateLife(int neighbors)
	{
		double prob = birthProbabilities[neighbors];
		double guess = Math.random();
		
		if(guess <= prob)
		{
			return true;
		}
		
		return false;
	}
	
	public ILifeRule deepRuleCopy()
	{
	    return new ProbabilisticLifeRule(survivalProbabilities,birthProbabilities,theColorGenerator,theName);
	}
	
	public String toString()
	{
	    return theName;
	}
	
	public String getRuleString()
	{
	    return "";
	}
}
	


